
//------------------------------------------------------------------------------

using Apps.Models;
using Apps.IDAL.CY;
using System;
using System.Linq;

namespace Apps.DAL.CY
{
    public partial class CY_MIX_PROJECTRepository : BaseRepository<CY_MIX_PROJECT>, ICY_MIX_PROJECTRepository, IDisposable
    {
        public CY_MIX_PROJECTRepository(DBContainer db) : base(db)
        {

        }

        public IQueryable<CY_MIX_PROJECTModel> QueryProjectList(DateTime dtQueryDate)
        {
            DateTime dtMin = Convert.ToDateTime(DateTime.MinValue.ToString("yyyy-MM-dd"));
            IQueryable<CY_MIX_PROJECTModel> list = from a in Context.CY_MIX_PROJECT
                                                   join c in Context.PUB_CREW on a.CREW_ID equals c.CREW_ID into crew
                                                   from tc in crew.DefaultIfEmpty()
                                                   join t in Context.PUB_TEAM on a.TEAM_ID equals t.TEAM_ID into team
                                                   from tt in team.DefaultIfEmpty()
                                                   join u in Context.SysUser on a.PROJECT_USER equals u.UserName into tuser
                                                   from tu in tuser.DefaultIfEmpty()
                                                   where a.PROJECT_DATE == dtQueryDate || dtQueryDate == dtMin
                                                   select new CY_MIX_PROJECTModel()
                                                   {
                                                       BEGIN_TIME = a.BEGIN_TIME,
                                                       CONDITION_ID = a.CONDITION_ID,
                                                       CREW_ID = a.CREW_ID,
                                                       CREW_NAME = tc.CREW_NAME,
                                                       END_TIME = a.END_TIME,
                                                       HOURS = a.HOURS,
                                                       IS_USED = a.IS_USED,
                                                       LOAD = a.LOAD,
                                                       LOAD_RATE = a.LOAD_RATE,
                                                       PROJECT_DATE = a.PROJECT_DATE,
                                                       PROJECT_ID = a.PROJECT_ID,
                                                       PROJECT_TIME = a.PROJECT_TIME,
                                                       PROJECT_USER = a.PROJECT_USER,
                                                       TEAM_ID = a.TEAM_ID,
                                                       TEAM_NAME = tt.TEAM_NAME,
                                                       PROJECT_USERName = tu.TrueName,
                                                       SEASON=a.CY_MIX_CONDITION.SEASON
                                                   };
            return list;
        }
    }
}
